<?php
class devtools_phrases_page extends page {

  protected $langs = array();
  protected $editlang = "it";
  protected $phrases = array();

  public function __construct() {
    //
  }
  
  public function prepare() {
    $editlang = request::get_url_var("editlang");
    if ($editlang!=null && strlen($editlang)>0) {
      $this->editlang = $editlang;
      system::$lang = $editlang;      
    }
    else
      $this->editlang = "it";
      
    $this->langs = config::get_supported_langs();
    $this->phrases = phrase::get_loaded_phrases();
    
    if (request::is_post()) {
      $uks = request::get_form_var("uks");
      $trans = request::get_form_var("trans");
      for ($index=0; $index<count($uks); $index++) {
        $phrase_uk = $uks[$index];
        $translation = $trans[$index];
        phrase::set_phrase($phrase_uk,$this->editlang,$translation);
      }
      phrase::save_all();
      $this->phrases = data::load_from_file("phrases");
    }//if
  }
  
  public function finish() {
  }

  public function render_block($block_name) {
    $block = $this->get_block($block_name);
    $block->render_html();
  }
}